//
//  FWSqaureButton.m
//  BirdLoveSheep
//
//  Created by wwj on 16/4/12.
//  Copyright © 2016年 wwj. All rights reserved.
//

#import "FWSqaureButton.h"
#import "FWSquareModel.h"
#import <UIButton+WebCache.h>

@implementation FWSqaureButton

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)coder{
    self = [super initWithCoder:coder];
    if (self) {
        [self initView];
    }
    return self;
}

- (void)setModel:(FWSquareModel *)model{
    _model = model;
    [self setTitle:model.name forState:UIControlStateNormal];
    [self sd_setImageWithURL:[NSURL URLWithString:model.icon] forState:UIControlStateNormal];
}

- (void)initView{
    [self setBackgroundImage:[UIImage imageNamed:@"mainCellBackground"] forState:UIControlStateNormal];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.font = [UIFont systemFontOfSize:15];
    [self setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.imageView.y = self.height * 0.15;
    self.imageView.width = self.width * 0.5;
    self.imageView.centerX = self.width * 0.5;
    self.imageView.height = self.imageView.width;
    
    self.titleLabel.x = 0;
    self.titleLabel.y = CGRectGetMaxY(self.imageView.frame);
    self.titleLabel.width = self.width;
    self.titleLabel.height = self.height - self.titleLabel.y;
    
    
}


- (void)setHighlighted:(BOOL)highlighted{}
@end
